﻿package core.ui.controls
{
    import core.enum.*;
    import core.ui.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class CanvasHolder extends Window
    {
        public var back:Sprite;
        public var ztb:NumberInput;
        public var imgsize:TextField;
        public var canvaswidth:int;
        public var canvasheight:int;
        public var coating:Coating;
        public var message:BubbleBack;
        public var grip:Sprite;
        public var binfo:Sprite;
        public var masking:Sprite;
        public var holder:Sprite;
        public var zoomer:Sprite;
        public var backdrop:Sprite;
        public var vscroll:WindowScroll;
        public var hscroll:WindowScroll;

        public function CanvasHolder(param1:Tuyitu, param2:String)
        {
            super(param1, param2, true);
            this.holder = new Sprite();
            addChild(this.holder);
            this.backdrop = new Sprite();
            this.holder.addChild(this.backdrop);
            this.masking = new Sprite();
            this.masking.graphics.beginFill(0);
            this.masking.graphics.drawRect(0, 0, 100, 100);
            this.masking.graphics.endFill();
            addChild(this.masking);
            this.holder.mask = this.masking;
            this.coating = new Coating(param1);
            addChild(this.coating);
            this.grip = new Sprite();
            this.grip.addEventListener(MouseEvent.MOUSE_OVER, this.GripMouseOver, false, 0, true);
            this.grip.addEventListener(MouseEvent.MOUSE_OUT, this.GripMouseOut, false, 0, true);
            this.grip.graphics.beginFill(11909049);
            this.grip.graphics.drawRect(0, 0, 16, 16);
            this.grip.graphics.endFill();
            var _loc_3:* = new Bitmap(new DragMark());
            var _loc_5:int = 4;
            _loc_3.x = 4;
            _loc_3.y = _loc_5;
            this.grip.addChild(_loc_3);
            addChild(this.grip);
            this.binfo = new Sprite();
            this.binfo.graphics.beginFill(14211289);
            this.binfo.graphics.drawRect(0, 0, 170, 16);
            this.binfo.graphics.beginFill(16777215);
            this.binfo.graphics.drawRect(0, 1, 45, 14);
            this.binfo.graphics.beginFill(11909049);
            this.binfo.graphics.drawRect(45, 1, 125, 14);
            this.binfo.graphics.endFill();
            this.ztb = new NumberInput(33, 100, 5, 800, false, false);
            this.ztb.y = -2;
            this.ztb.t.tabEnabled = false;
            this.binfo.addChild(this.ztb);
            var _loc_4:* = new Literal("%");
            _loc_4.x = 28;
            _loc_4.y = -1;
            this.binfo.addChild(_loc_4);
            this.imgsize = new TextField();
            this.imgsize.defaultTextFormat = new TextFormat("Verdana,Helvetica,San-serif", 10, 0, false, false, false, null, null, "center");
            this.imgsize.height = 18;
            this.imgsize.multiline = false;
            this.imgsize.selectable = false;
            this.imgsize.width = 120;
            this.imgsize.x = 46;
            this.imgsize.y = 0;
            this.binfo.addChild(this.imgsize);
            this.binfo.x = 4;
            this.binfo.y = this.height - 20;
            addChild(this.binfo);
            this.vscroll = new WindowScroll(Direction.Vertical, 0, 0);
            this.vscroll.y = 22;
            addChild(this.vscroll);
            this.hscroll = new WindowScroll(Direction.Horizontal, 0, 0, 170);
            this.hscroll.x = 174;
            addChild(this.hscroll);
            this.back = new Sprite();
            this.back.graphics.beginFill(16711680, 0);
            this.back.graphics.drawRect(0, 0, 100, 100);
            this.back.graphics.endFill();
            this.back.x = 4;
            this.back.y = 22;
            addChild(this.back);
            this.message = new BubbleBack(this.back);
            addChild(this.message);
            return;
        }// end function

        public function SetImageSizeInfo(multiline:int, multiline:int) : void
        {
            this.imgsize.text = multiline + "x" + multiline + " px";
            return;
        }// end function

        override public function Resize(multiline:int, multiline:int, multiline:Boolean = false) : void
        {
            if (multiline < 270)
            {
                multiline = 270;
            }
            if (multiline < 170)
            {
                multiline = 170;
            }
            super.Resize(multiline, multiline, false);
            if (!multiline)
            {
                this.grip.x = multiline - 20;
                this.grip.y = multiline - 20;
            }
            this.vscroll.x = multiline - 20;
            this.vscroll.SetSize(multiline - 42);
            this.hscroll.y = multiline - 20;
            this.hscroll.SetSize(multiline - 194);
            this.binfo.y = multiline - 20;
            this.canvaswidth = this.grip.x - 4;
            this.canvasheight = this.grip.y - 22;
            this.back.width = this.canvaswidth;
            this.back.height = this.canvasheight;
            if (this.backdrop.width < this.canvaswidth || this.backdrop.height < this.canvasheight)
            {
                this.backdrop.graphics.beginBitmapFill(new TransparentLarge());
                this.backdrop.graphics.drawRect(0, 0, this.canvaswidth + 100, this.canvasheight + 100);
                this.backdrop.graphics.endFill();
            }
            return;
        }// end function

        public function GripMouseOver(event:MouseEvent) : void
        {
            ed.cursor.Set(ToolType.ResizeHeightWidth);
            return;
        }// end function

        public function GripMouseOut(event:MouseEvent) : void
        {
            ed.cursor.Set(ToolType.None);
            return;
        }// end function

        public function CloseClick(event:MouseEvent) : void
        {
            ed.cm.ConfirmClose();
            return;
        }// end function

        public function MaxClick(event:MouseEvent) : void
        {
            AppState.Maximized = true;
            ed.MaxMinCanvas();
            ed.options.UpdateCanvasList();
            return;
        }// end function

    }
}
